package com.talkweb.historylib.provider;

import com.talkweb.historylib.ResourceTable;
import com.talkweb.securitycamera.common.interfaces.entity.IBaseFileEntity;
import com.talkweb.securitycamera.utils.photocodeclib.PhotoDecode;
import ohos.aafwk.ability.Ability;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.utils.TextTool;
import ohos.media.image.PixelMap;

/**
 * @author SUQI
 * @date 2021/1/29
 * @description 视频历史列表适配器
 **/
public class VideoListProvider extends BaseListProvider<IBaseFileEntity> {

    public VideoListProvider(Ability mContext) {
        super(mContext);
    }

    @Override
    protected void onBindViewHolder(ViewHolder viewHolder, IBaseFileEntity data, int position) {
        if (data == null) {
            return;
        }
        Text tvName = viewHolder.getView(ResourceTable.Id_tv_name);
        tvName.setText(TextTool.isNullOrEmpty(data.getFileName()) ? "" : data.getFileName());

        Text tvDuration = viewHolder.getView(ResourceTable.Id_tv_duration);
        tvDuration.setText(TextTool.isNullOrEmpty(data.getCreateDuration()) ? "" : data.getCreateDuration());
        Image ivIcon = viewHolder.getView(ResourceTable.Id_iv_icon);
        PixelMap pixelMap = new PhotoDecode.Builder().build().commonDecodePhoto(data.getFilePath());
        if (pixelMap != null) {
            ivIcon.setPixelMap(pixelMap);
        }
    }

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_item_view_video_list;
    }
}
